package org.gcb.core.model;

import java.util.HashSet;
import java.util.Set;
import javax.swing.event.SwingPropertyChangeSupport;
import org.gcb.core.model.util.Utilities;

/**
 *
 * @author Jason
 */
public class Weapon extends Item implements IEquippable<EWeaponSlot> {
    public static final String PROP_RANGE = "range";
    public static final String PROP_ENHANCEMENT = "enhancement";
    public static final String PROP_DMG_ENHANCEMENT = "dmgEnhancement";
    public static final String PROP_DAMAGE = "damage";
    public static final String PROP_NOTES = "notes";
    private final Set<MiscModifier<?, Integer>> modifiers = new HashSet<MiscModifier<?, Integer>>(0);
    private final Set<MiscModifier<?, Integer>> dmgModifiers = new HashSet<MiscModifier<?, Integer>>(0);
    private final Toon toon;
    private final EWeaponSlot slot;
    private SwingPropertyChangeSupport propSupport = new SwingPropertyChangeSupport(this, true);
    /** */
    private Object range;
    private Integer enhancement;
    private Integer dmgEnhancement;
    private Object damage;
    private String notes;

    /**
     * This class will require some text mathematic parsing.
     * @param toon
     */
    public Weapon(String text, String description, Double weight, Toon toon, EWeaponSlot slot) {
        super(null, text, description, weight);
        this.toon = toon;
	this.slot = slot;
    }

    public Object getDamage() {
        return damage;
    }

    public void setDamage(Object damage) {
        Object oldDamage = this.damage;
        this.damage = damage;
        propSupport.firePropertyChange(PROP_DAMAGE, oldDamage, this.damage);
    }

    public Integer getDmgEnhancement() {
        return dmgEnhancement;
    }

    public void setDmgEnhancement(Integer dmgEnhancement) {
        Integer oldDmgEnhancement = this.dmgEnhancement;
        this.dmgEnhancement = dmgEnhancement;
        propSupport.firePropertyChange(PROP_DMG_ENHANCEMENT, oldDmgEnhancement, this.dmgEnhancement);
    }

    public Set<MiscModifier<?, Integer>> getDmgModifiers() {
        return dmgModifiers;
    }

    public Integer getEnhancement() {
        return enhancement;
    }

    public void setEnhancement(Integer enhancement) {
        Integer oldEnhancement = this.enhancement;
        this.enhancement = enhancement;
        propSupport.firePropertyChange(PROP_ENHANCEMENT, oldEnhancement, this.enhancement);
    }

    public Set<MiscModifier<?, Integer>> getModifiers() {
        return modifiers;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        String oldNotes = this.notes;
        this.notes = notes;
        propSupport.firePropertyChange(PROP_NOTES, oldNotes, this.notes);
    }

    public Object getRange() {
        return range;
    }

    public void setRange(Object range) {
        Object oldRange = this.range;
        this.range = range;
        propSupport.firePropertyChange(PROP_RANGE, oldRange, this.range);
    }

    public Integer getAttackModifier() {
        Integer attackModifier = 0;
        Integer halfLevel = toon.getLevel()/2;
        Integer proficiency = 0;//possibly from toon.getProficiencies().get(EProficiencyType)==null?0:val;
        Integer enhance = this.enhancement;
        Integer miscMods = 0;//Utilities.calculateMiscModifier(modifiers);
        attackModifier = halfLevel + proficiency + enhance + miscMods;
        return attackModifier;
    }

    public Integer getDamageBonus() {
        Integer dmgBonus = 0;
        Integer feat = 0;//from toon.getFeats().???
        Integer enhance = this.dmgEnhancement;
        Integer miscMods = 0;//Utilities.calculateMiscModifier(dmgModifiers);
        dmgBonus = feat + enhance + miscMods;
        return dmgBonus;
    }

    @Override
    public EWeaponSlot getSlot() {
	return slot;
    }
}
